package cn.mcsys.viewer.core.listener;

import cn.mcsys.viewer.core.listener.thread.SocketThread;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author bobo
 * @create 2018-09-17 14:54
 * @desc ${DESCRIPTION}
 **/
public class SocketServiceLoader implements ServletContextListener {

    public static WebApplicationContext webApplicationContext;

    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        new SocketThread(webApplicationContext).start();
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }

    public static WebApplicationContext getWebApplicationContext(){
        return webApplicationContext;
    }
}
